package edu.tyut.game.logic

import edu.tyut.game.logic.Repository.fire
import edu.tyut.game.logic.model.User
import edu.tyut.game.logic.network.GameNetWork

object MailRepository {

    /**
     * 发送邮箱验证码
     */
    fun sendMail(user: User) = fire {
        val res = GameNetWork.sendMail(user)
        if (res.status == "ok") {
            Result.success(res.data)
        } else {
            Result.failure(Exception("邮件发送失败: ${res.msg}"))
        }
    }

    fun sendRetrievePasswordEmail(user: User) = fire {
        val res = GameNetWork.sendRetrievePasswordEmail(user)
        if (res.status == "ok"){
            Result.success(res.data)
        }else{
            Result.failure(Exception("找回密码邮件发送失败：${res.msg}"))
        }
    }
}